package Day07;
import java.util.Arrays;
import java.util.Scanner;
public class CalTotalAvg {
    public static void main(String[] args) {
//        Scanner input1 = new Scanner(System.in);
//        System.out.print("要输入几位评委的分数：");
//        int number = input1.nextInt();
//        double[] score1 = score1(number);
//        travel(score1);                  //第一行
//        System.out.println();
//        double[] score2 = maxMin(score1);
//        System.out.println("去掉最大最小后的分数：");
//        travel(score2);
//        System.out.println();
//        System.out.print("总分为：");
//        System.out.println(sum(score2));
//        System.out.print("平均值为：");
//        System.out.println(average(score1));


        //第二种
        Scanner input1 = new Scanner(System.in);
        System.out.print("要输入几位评委的分数：");
        int number = input1.nextInt();
        double[] score1 = score1(number);
        travel(score1);
        System.out.println();
        System.out.print("总分为：");
        double score2 = sum(score1);
        System.out.println(score2);
        System.out.print("去掉最大最小值后的总分：");
        double score3 = sum2(score1);
        System.out.println(score3);
        System.out.print("平均值为：");
        System.out.println(average(score1));


    }
    //录入成绩
    public static double[] score1 (int m) {
        Scanner input1 = new Scanner(System.in);
        double[] score = new double[m];
        for (int i=0;i<score.length;i++) {
            System.out.print("请输入第"+(i+1)+"位评委的分数：");
            score[i] = input1.nextDouble();
        }
        return score;
    }
    //求最大值和最小值
    public static double max (double a[]) {
        double max = a[0];
        for (int i=1;i<a.length;i++) {
            if (a[i]>max) {
                max = a[i];
            }
        }
        return max;
    }
    public static double min (double a[]) {
        double min = a[0];
        for (int i=1;i<a.length;i++) {
            if (a[i]<min) {
                min = a[i];
            }
        }
        return min;
    }
    //求和
    public static double sum (double[] a) {
        int sum = 0;
        for (int i=0;i<a.length;i++) {
            sum += a[i];
        }
        return sum;
    }
    //减去最大最小值后的总分
    public static double sum2 (double[] a) {
        double sum2 = sum(a) - max(a) - min(a);
        return sum2;
    }
    //求平均值
    public static double average (double[] a) {
        double sum = sum2(a);
        double average = sum/(a.length-2);
        return average;
    }

    //遍历数组
    public static void travel (double[] a) {
        for (int i=0;i<a.length;i++) {
            System.out.print(a[i]+"\t");
        }
    }
    //排序并减去最大值和最小值
    public static double[] maxMin (double[] a) {
        Arrays.sort(a);
        double[] b = new double[a.length-2];
        System.arraycopy(a,1,b,0,a.length-2);
        return b;
    }
 }
